

/**
 * 数组操作
 */
public class PracticsString {
    public static void main(String[] args) {

        /*
         * String常用方法
         *
         */
        /**************************第一部分**************************/

        //判断是否为空----长度为0就为空
        String str = "";
        String str1 = "we";
        System.out.println(str.isEmpty());
        System.out.println(str1.isEmpty());

        //求长度
        String str2 = "hello boy";
        System.out.println(str2.length());

        //获取某个位置的字符
        String str3 = "world";
        System.out.println(str3.charAt(3));

        //判断内容相同
        String str4 = "world";
        String str5 = "world";
        String str6 = "worl";
        System.out.println(str4.equals(str5));
        System.out.println(str4.equals(str6));

        //判断内容相同，忽略大小写
        String str7 = "world";
        String str8 = "WORLD";
        System.out.println(str7.equalsIgnoreCase(str8));


        //把各种数据类型的数据转为字符串： 数组 object boolean char int long float double
        char[] chars2 = {'h', 'i', ' ', 'e', 'v', 'e', 'y', 'o', 'n', 'e'};
        System.out.println(String.valueOf(chars2));

        Object obj = "good day";
        System.out.println(String.valueOf(obj));

        boolean b = true;
        System.out.println(String.valueOf(b));

        char s = 'f';
        System.out.println(String.valueOf(s));

        int g = 100;
        System.out.println(String.valueOf(g));

        long l = 100L;
        System.out.println(String.valueOf(l));

        float ft = 3.14f;
        System.out.println(String.valueOf(ft));

        double d = 100.23;
        System.out.println(String.valueOf(d));

        //分割字符串-1
        String str0_16 = "hi go everone go here go is go";
        String[] chars0 = str0_16.split("go");
        System.out.println("分割字符串-1");
        for (int i = 0; i < chars0.length; i++) {
            System.out.println(chars0[i]);
        }

        //分割字符串-1
        String str16 = "hi everone here is go";
        String[] chars = str16.split(" ");
        for (int i = 0; i < chars.length; i++) {
            System.out.println(chars[i]);
        }

        //字符串转大小写
        String str17 = "hi everone here is go";
        System.out.println(str17.toUpperCase());
        System.out.println(str17.toLowerCase());

        //字符串去除左右空格
        String str18 = "  hi everone here is go  ";
        System.out.println(str18.trim());

        //把字符串转为数组
        String str19 = "hi everone here is go";
        char[] chars1 = str19.toCharArray();
        for (int i = 0; i < chars1.length; i++) {
            System.out.println(chars1[i]);
        }

        //格式化字符串
        String str20 = "hi %s";
        System.out.println(String.format(str20, "bella"));


        //判断字符串以什么开头
        String str9 = "hi everyone";
        System.out.println(str9.startsWith("hi"));
        System.out.println(str9.startsWith("everyone"));

        //判断字符串以什么结尾
        String str10 = "hi everyone";
        System.out.println(str10.endsWith("hi"));
        System.out.println(str10.endsWith("everyone"));

        //截取字符串
        String str11 = "hi everyone";
        System.out.println(str11.substring(2, 5));

        //连接两个字符串
        String str12 = "hi";
        String str13 = " everyone";
        System.out.println(str12.concat(str13));
        //注：也可以直接用+号

        //替换字符串中特定字符
        String str14 = "hi everyone";
        System.out.println(str14.replace("hi", "hello"));

        //字符串是否包含某些内容
        String str15 = "hi everyone";
        System.out.println(str15.contains("o"));
        System.out.println(str15.contains("w"));


    }
}
